using System;
using System.Collections.Generic;
using System.Text;
using SpriteCraft;
using System.Drawing;

namespace SpaceGame
{
  public class SCEngine : Engine
  {
    private EngineClass m_Engine;

    public SCEngine()
    {
      m_Engine = new EngineClass();
    }

    public override void Init()
    {
      m_Engine.logging = true;

      m_Engine.Init(tagScDevice.DevAuto);
      m_Engine.background.color = Color.White.ToArgb();
      m_Engine.SST = "media/SST.txt";
      m_Engine.PlaceWindowAt(tagPosition.PositionCenter);
      m_Engine.showFps = true;
    }

    public override void Run()
    {
      bool doRestart = false;

      do
      {
        if (m_Engine.EvtIsESC() || m_Engine.EvtIsQuit()) { break; }

        if (m_Engine.NextEvent())
        {
          if (m_Engine.EvtIsKeyDown() && m_Engine.EvtKey() == tagKeyVal.Key_F4)
          {
            m_Engine.fullscreen = !m_Engine.fullscreen;
          }

          if (m_Engine.EvtIsKeyDown()
            && m_Engine.EvtKey() == tagKeyVal.Key_F12)
          {
            doRestart = true;
            break;
          }
        }

        m_Engine.DisplayEx(30);
      } while (true);

      m_Engine.Purge();
      if (!doRestart)
      {
        m_Engine = null;
      }
      else
      {
        Program.Restart();
      }
    }

    public override EngineClass GetEngine()
    {
      return m_Engine;
    }
  }
}
